package com.example.zhongcao.controller;

import com.example.zhongcao.exception.InvalidParam;
import com.example.zhongcao.service.SignService;
import com.example.zhongcao.utils.Message;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("sign")
public class SignController {

    @Resource
    SignService signService;
    @RequestMapping(value="buildUserSigns",method = RequestMethod.GET)
    public Message buildUserSigns(@RequestParam("openid")String openid, @RequestParam("sign")String sign){
        String msg=null;
        try {
            msg="添加成功，再继续逛逛吧!";
            signService.buildUserSign(openid,sign);
            return Message.createSuc(msg);
        } catch (InvalidParam e) {
            msg=e.getErrmsg();
            System.out.println(e.getErrmsg());
        }
        return Message.createErr(msg);
    }

    @RequestMapping(value = "getSigns",method = RequestMethod.GET)
    public Message getSigns(@RequestParam("type")String type,@RequestParam(value = "openid",required = false)String openid,
                            @RequestParam(value = "zhongcaoid",required = false)Integer zhongcaoid){
        String msg=null;
        try {
            return Message.createSuc(signService.getSigns(type, openid, zhongcaoid));
        } catch (InvalidParam e) {
            msg=e.getErrmsg();
            System.out.println(e.getErrmsg());
        }
        return Message.createErr(msg);
    }
}
